home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Audio / LPCView / Source / PWSpectrum.psw < prev   
Encoding:
Text File  |  1992-03-07  |  2.8 KB  |  98 lines

  1. /* PWspectrum -- pswrap-able code for SpectrumView
  2.  * 
  3.  * This file includes:
  4.  *    PWSpectinit()         -- Initializes variables
  5.  *    PWSpectdrawHruler()    -- Draws the horizontal (time) ruler
  6.  *    PWSpectdrawVruler()    -- Draws the vertical (frequency) ruler
  7.  *    PWSmeanplotdata()    -- Draws one point of mean frequency data
  8.  *
  9.  * smb@datran2.uunet.uu.net
  10.  * jwp@silvertone.Princeton.edu
  11.  * 2/90
  12.  * 03/90:  Removed PWSpectplotdata() (now done in SpectrumView)
  13.  */
  14.  
  15. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  16.  
  17. /* PWSpectinit() -- Initialize variables
  18.  *     'Spectrulerfont' = font for the rulers
  19.  *    'lastmeany' = last mean frequency data point
  20.  */
  21. defineps PWSpectinit()
  22.     /Spectrulerfont /Helvetica findfont 8 scalefont def 
  23.     /lastmeany -1 def
  24. endps
  25.  
  26. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  27.  
  28. /* PWSpectdrawHruler -- draws the X-axis hashmarks and seconds numbers
  29.  * Arguments:  nmin, nmax, dn = controls for loop (these are sec. vals)
  30.  *            dx             = distance between hashmarks (in pixels)
  31.  * Display is always 20 pixels high.
  32.  * BUG: last # tends to get clipped.
  33.  */
  34.  
  35. defineps PWSpectdrawHruler(float nmin,nmax,dn,dx)
  36.     /*Spectrulerfont setfont*/
  37.     /Helvetica findfont 8 scalefont setfont
  38.     0 setgray
  39.     gsave
  40.     nmin dn nmax {
  41.         0 5 moveto        % Use 'translate' to locate
  42.         (    ) cvs show        % Convert n to string and print
  43.         0 15 moveto        % Draw the hash mark
  44.         0 5 rlineto
  45.         stroke
  46.         dx 0 translate        % Move over by dx for next
  47.     } for                % for (n = nmin; n <= nmax; n += dn)
  48.     grestore
  49. endps
  50.  
  51. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  52.  
  53. /* PWSpectdrawVruler -- draws the Y-axis hashmarks and KHz numbers
  54.  * Arguments:  nmin, nmax, dn = controls for loop (these are KHz vals)
  55.  *            dy             = distance between hashmarks
  56.  * Display is always 30 pixels wide.
  57.  * BUG: last # tends to get clipped.
  58.  */
  59.  
  60. defineps PWSpectdrawVruler(int nmin,nmax,dn; float dy)
  61.     Spectrulerfont setfont
  62.     0 setgray
  63.     gsave
  64.     nmin dn nmax {
  65.         10 0 moveto        % Use 'translate' to locate
  66.         (    ) cvs show        % Convert n to string and print
  67.         25 0 moveto        % Draw the hash mark
  68.         5 0 rlineto
  69.         stroke
  70.         0 dy translate        % Move over by dx for next
  71.     } for                % for (n = nmin; n <= nmax; n += dn)
  72.     grestore
  73. endps
  74.  
  75. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  76.  
  77. /* PWSmeanplotdata -- Plots the mean frequency line
  78.  * Arguments:    index     = vertical index of the mean line
  79.  *        dx         = distance between points (horizontally)
  80.  *        yscale    = scaling factor (vertical)
  81.  */
  82.  
  83. defineps PWSmeanplotdata(int index; float dx,yscale)
  84.     0 setgray 1 setlinewidth
  85.  
  86.     /meany index yscale mul def        % meany = index * yscale
  87.     lastmeany 0 ge {            % if last > 0
  88.             % draw a line from (-dx,lastmeany) to (0,meany)
  89.         newpath
  90.             0 dx sub lastmeany moveto
  91.             0 meany lineto
  92.         stroke
  93.     } if 
  94.     /lastmeany meany def        % update lastmeany
  95. endps
  96.  
  97.  
  98.